/**
 * Queen.
 * 
 * @author Brian Boadi, Antoine Domenger
 * @version 1.0
 */

package lp.chess;

public class Queen extends Piece {
	//- CONSTRUCTOR(S) ------------------------------------------------------------------------

	/**
 	 * Default constructor.
 	 * Initializes an empty queen.
 	 */
	public Queen() {
		super();
	}

	/**
	 * Initializes a new queen of a given color.
	 * 
	 * @param white true if the queen must be white, false if it must be black.
	 */
	public Queen(boolean white) {
		super(white);
	}
	
	/**
	 * Initializes a new queen with all of its attributes.
	 * 
	 * @param x	the x coordinate of the queen on the chessboard.
	 * @param y the y coordinate of the queen on the chessboard.
	 * @param white true if the queen must be white, false if it must be black.
	 */
	public Queen(int x, int y, boolean white) {
		super(x, y, white);
	}
	
	/**
	 * Copy constructor.
	 * Initializes a new queen from a given one.
	 * 
	 * @param other the queen to copy in the new one.
	 */
	public Queen(Queen other) {
		super(other);
	}
	
	//-----------------------------------------------------------------------------------------

	//- OTHER METHOD(S) -----------------------------------------------------------------------

	/**
	 * Checks if a move is valid for this kind of piece.
	 * 
	 * @param cb the chessboard.
	 * @param x	the x coordinate where we want the queen to move on the chessboard.
	 * @param y the y coordinate where we want the queen to move on the chessboard.
	 * @param act true if we want to remove the piece that can be taken.
	 * 
	 * @return true if the move is valid.
	 */
	public boolean validMove(Chessboard cb, int x, int y, boolean act)
	{
		boolean isValid = (cb.isOutOfRange(x, y) && differentPosition(x, y));
		Piece dummy;
		
		if(x == getX() || y == getY()) {	// It tries to move like a rook.
			dummy = new Rook(getX(), getY(), isWhite());
			isValid = dummy.validMove(cb, x, y, act);
		}
		else {	// It tries to move like a bishop.
			dummy = new Bishop(getX(), getY(), isWhite());
			isValid = dummy.validMove(cb, x, y, act);
		}
		
		return isValid;
	}

	/**
	 * Returns the character associated to the type of this piece.
	 * 
	 * @return the character associated to the type of this piece 
	 */
	public char getType()
	{
		if(isWhite()) return 'Q';
		else return 'q';
	}
	
	/**
	 * Returns a copy of this piece.
	 * 
	 * @return a copy of this piece.
	 */
	public Piece getCopy() {
		Queen copy = new Queen(m_x, m_y, m_white);
		
		return copy;
	}
	
	//-----------------------------------------------------------------------------------------
}
